package com.itheima.controller;

import com.itheima.pojo.User;
import com.itheima.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("user")
public class UserController {

    @Value("${server.port}")
    int port;

    @Autowired
    UserService userService;

    @RequestMapping("{id}")
    public User findById(@PathVariable("id") String id, HttpServletRequest request){

        String name = request.getHeader("name");
        System.out.println("请求头name = " + name);
        System.out.println("post = " + port);

        //测试线程隔离时间
/*        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }*/

        User byId = userService.findById(id);
        byId.setEmail("port:"+port);
        return byId;
    }

}
